package com.leyou.upload.web;

import com.leyou.upload.service.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author xiuer
 * @description 文件上传控制层
 * @create 2019/6/25 16:28
 */
@RestController
public class UploadFileController {

    @Autowired
    private UploadFileService uploadFileService;

    /**
     * 本地上传图片功能
     *
     * @param file
     * @return
     */
    @PostMapping("image")
    public ResponseEntity<String> uploadimage(@RequestParam("file") MultipartFile file) {
        return ResponseEntity.ok(uploadFileService.uploadimage(file));
    }

    /**
     * 阿里云OSS文件上传
     */
    @GetMapping("signature")
    public ResponseEntity<Map<String, Object>> getAliSignature() {
        return ResponseEntity.ok(uploadFileService.getSignature());
    }
}

